package com.zw.admin.server.model;



public class ResponseBean<T> {

    private Integer code;

    private String msg;

    private T data;

    public ResponseBean(){}

    public ResponseBean(T data, Integer code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    /**
     * 成功时将object对象转化为ResultBean对象
     *
     * @param o
     * @return ResponseBean
     */
    public static ResponseBean ok(Object o) {

        return new ResponseBean(o, ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg());
    }

    /**
     * 成功时将object对象转化为ResultBean对象
     *
     * @param
     * @return ResponseBean
     */
    public static ResponseBean ok() {

        return new ResponseBean(null, ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg());
    }
    /**
     * 异常转化为ResultBean对象
     *
     * @param responseEnum
     * @return
     */
    public static ResponseBean error(ResponseEnum responseEnum) {
        return new ResponseBean(null, responseEnum.getCode(), responseEnum.getMsg());
    }

    /**
     * 异常转化为ResultBean对象
     *
     * @param code
     * @param msg
     * @return
     */
    public static ResponseBean error(Integer code, String msg) {
        return new ResponseBean(null, code, msg);
    }

    @Override
    public String toString() {
        return "ResponseBean{" +
                ", data=" + data +
                ", code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                '}';
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}